<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">

    <title>SSE</title>
</head>
<body>
    <div id="example"></div>
    <script>
        var div = document.getElementById('example');
        var uri = 'http://127.0.0.1:5227/app/infos';

        var source = new EventSource(uri);

        source.onopen = function (event) {
            div.innerHTML += '<p>Connection open ...</p>';
        };
        source.onerror = function (event) {
            div.innerHTML += '<p>Connection close.</p>';
            // source.close()
        };

        source.addEventListener('connecttime', function (event) {
            div.innerHTML += ('<p>Start time: ' + event.data + '</p>');
        }, false);
        source.addEventListener('close', function (event) {
            div.innerHTML += '<p>Event close.</p>';

            source.close()
        }, false);

        source.onmessage = function (event) {
            div.innerHTML += ('<p>Ping: ' + event.data + '</p>');
        };

        // let sse = new EventSource('http://127.0.0.1:5227/app/infos');
        // sse.onmessage = console.log()
    </script>
</body>
</html>
